/**
 * Created by chenyong on 2015/7/16.
 */

function InternalOAuthError(message, err) {
    Error.call(this);
    Error.captureStackTrace(this, arguments.callee);
    this.name = 'InternalOAuthError';
    this.message = message;
    this.oauthError = err;
}

InternalOAuthError.prototype.__proto__ = Error.prototype;

InternalOAuthError.prototype.toString = function() {
    var m = this.name;
    if (this.message) { m += ': ' + this.message; }
    if (this.oauthError) {
        if (this.oauthError instanceof Error) {
            m = this.oauthError.toString();
        } else if (this.oauthError.statusCode && this.oauthError.data) {
            m += ' (status: ' + this.oauthError.statusCode + ' data: ' + this.oauthError.data + ')';
        }
    }
    return m;
};

module.exports = InternalOAuthError;